struc FileRecord {
	.attr		= 0x00
	.filesize	= 0x04
	.year_crt	= 0x08
	.month_crt	= 0x09
	.day_crt	= 0x0A
	.hour_crt	= 0x0B
	.min_crt	= 0x0C
	.sec_crt	= 0x0D
	.year_acc	= 0x0E
	.month_acc	= 0x0F
	.day_acc	= 0x10
	.hour_acc	= 0x11	      
	.min_acc	= 0x12
	.sec_acc	= 0x13
	.year_lstr	= 0x14
	.month_lstr	= 0x15
	.day_lstr	= 0x16
	.hour_lstr	= 0x17
	.min_lstr	= 0x18
	.sec_lstr	= 0x19
	.year_lstw	= 0x1A
	.month_lstw	= 0x1B
	.day_lstw	= 0x1C
	.hour_lstw	= 0x1D
	.min_lstw	= 0x1E
	.sec_lstw	= 0x1F
	.shortname	= 0x20
	.longname	= 0x30 
	.Size		= 0xFF
}
frec FileRecord

;===============================
; Get file extension
;-------------------------------
; IN: esi - pointer to filename
;     edi - buffer
;===============================
get_ext:
.@next:
    mov al,[esi]
    cmp al,'.'
    je .@dot_found
    cmp al,0
    je .@not_found
    inc esi
    jmp .@next
.@dot_found:
    mov al,[esi]
    cmp al,0
    je .@end
    mov [edi],al
    inc esi
    inc edi
    jmp .@dot_found
.@not_found:
.@end:
    ret


find_and_show_files:
	mov	[icon_x_win],20
	mov	[icon_y_win],40
	pusha
	mov	eax,0
      reading_dir:
	invoke	FindFile, Path, fileinfo, eax
	cmp	[fileinfo+frec.shortname],byte 0
	je	exit_reading_dir

	pusha
	  mov esi,fileinfo+frec.shortname
	  mov edi,ext
	  call get_ext
	  cmp  dword [ext],'.ico'
	  jne .@no_icon
	  jmp .@ok
      .@no_icon:
	  cmp  dword [ext],'.cur'
	  jne .@no_cursor
      .@ok:
	  stdcall draw_icon,[icon_x_win],[icon_y_win],fileinfo+frec.shortname
	  add [icon_y_win],34
	  invoke WriteText,[icon_x_win],[icon_y_win],0,4,fileinfo+frec.shortname
	  sub [icon_y_win],34
	  add [icon_x_win],70
	  cmp [icon_x_win],400
	  jbe .@n_above
	  mov [icon_x_win],20
	  add [icon_y_win],46
.@n_above:
      .@no_cursor:
	popa

	inc	eax
	jmp	reading_dir
      exit_reading_dir:
	popa
	ret